package com.ulook.lookplanet.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.qmuiteam.qmui.layout.QMUIFrameLayout;
import com.qmuiteam.qmui.skin.QMUISkinHelper;
import com.qmuiteam.qmui.skin.QMUISkinManager;
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.widget.popup.QMUIFullScreenPopup;
import com.qmuiteam.qmui.widget.popup.QMUIPopups;
import com.ulook.lookplanet.R;
import com.ulook.lookplanet.base.WidgetData;
import com.ulook.lookplanet.ui.square.article.VCommentInfo;
import com.ulook.lookplanet.util.StringUtil;

/**
 * 描述：
 *
 * @author L1998
 * @data 2021/4/21
 */
public class CommentView extends LinearLayout implements WidgetData<VCommentInfo> {

    private Context context;
    private int currUserId;
    private VCommentInfo comment;

    public CommentView(Context context) {
        super(context);
        initCommentView(context);
    }

    public CommentView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initCommentView(context);
    }

    public CommentView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initCommentView(context);
    }

    private void initCommentView(Context context){
        this.context = context;
        LayoutInflater.from(context).inflate(R.layout.widget_comment_view, this, true);
    }

    @Override
    public void setWidgetData(VCommentInfo value) {
        this.comment = value;
        TextView user = findViewById(R.id.w_comment_user_name);
        TextView replay = findViewById(R.id.w_comment_replay);
        TextView time = findViewById(R.id.w_comment_time);
        TextView content = findViewById(R.id.w_comment_content);

        user.setText(comment.getName() + ":");
        if(!StringUtil.isEmpty(comment.getReplayname())){
            replay.setVisibility(VISIBLE);
            replay.setText("回复@" + comment.getReplayname());
        }else {
            replay.setVisibility(GONE);
        }
        time.setText(comment.getPubtime().subSequence(5, 16));
        content.setText(comment.getContent());

        // 点击评论回复
        /*content.setClickable(true);
        content.setOnClickListener(view -> {

        });*/
        // 点击名字跳转用户页面
    }

    @Override
    public void setWidgetData(VCommentInfo value, int currUserID) {
        this.currUserId = currUserID;
        setWidgetData(value);
    }

    public VCommentInfo getCommentInfo(){
        return comment;
    }
}
